﻿using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using System.Windows.Input;

namespace wpapp
{

    public partial class Page2 : PhoneApplicationPage
    {
        String pdtn;
        product p = new product();
        public Page2()
        {
            
            InitializeComponent();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (NavigationContext.QueryString["pdtn"] != null)
            {

                this.pdtn = NavigationContext.QueryString["pdtn"];
            }

            p = App.products.Where(h => h.imgurl == pdtn).FirstOrDefault();
            this.theimg.Source = new BitmapImage(new Uri(p.imgurl.ToString(), UriKind.Relative));
            this.thepdtn.Text = p.productname.ToString();
            this.thepdttime.Text = p.time.ToString();
        }

        private void TextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (NavigationContext.QueryString["pdtn"] != null)
            {

                this.pdtn = NavigationContext.QueryString["pdtn"];
            }
            TextBox tbx = (TextBox)sender;

            if (e.Key == Key.Enter & p != null)
            {
                if (App.logid!=null)
                {
                    App.products.Where(h => h.imgurl == pdtn).FirstOrDefault().pdtrv.Add(new review { pinglun = tbx.Text, pltime =App.logid.ToString()+"发表于"+ System.DateTime.Now.ToString() });
                this.Focus();
                } 
                else
                {
                    App.products.Where(h => h.imgurl == pdtn).FirstOrDefault().pdtrv.Add(new review { pinglun = tbx.Text, pltime = "发表于" + System.DateTime.Now.ToString() });
                    this.Focus();
                }
                
            }
        }

        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            InitializeComponent();
            if (NavigationContext.QueryString["pdtn"] != null)
            {

                this.pdtn = NavigationContext.QueryString["pdtn"];
            }
            this.lbReviews.ItemsSource = App.products.Where(h => h.imgurl == pdtn).FirstOrDefault().pdtrv.ToList();
        }

       
    }
}